<?php

/**
 * EmsSection form base class.
 *
 * @method EmsSection getObject() Returns the current form's model object
 *
 * @package    ems1
 * @subpackage form
 * @author     Jacobo Martínez
 * @version    SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
 */
abstract class BaseEmsSectionForm extends BaseFormDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'id'                    => new sfWidgetFormInputHidden(),
      'title'                 => new sfWidgetFormInputText(),
      'slug'                  => new sfWidgetFormInputText(),
      'is_subsection'         => new sfWidgetFormInputCheckbox(),
      'has_subsection'        => new sfWidgetFormInputCheckbox(),
      'max_contents_per_page' => new sfWidgetFormInputText(),
      'structure'             => new sfWidgetFormInputText(),
      'uses_header'           => new sfWidgetFormInputCheckbox(),
      'uses_footer'           => new sfWidgetFormInputCheckbox(),
      'published'             => new sfWidgetFormInputCheckbox(),
      'is_enabled'            => new sfWidgetFormInputCheckbox(),
      'portal_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Portal'), 'add_empty' => false)),
      'type_id'               => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Type'), 'add_empty' => false)),
      'parent_id'             => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('Parent'), 'add_empty' => true)),
      'created_at'            => new sfWidgetFormDateTime(),
      'updated_at'            => new sfWidgetFormDateTime(),
    ));

    $this->setValidators(array(
      'id'                    => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
      'title'                 => new sfValidatorString(array('max_length' => 100)),
      'slug'                  => new sfValidatorString(array('max_length' => 255)),
      'is_subsection'         => new sfValidatorBoolean(array('required' => false)),
      'has_subsection'        => new sfValidatorBoolean(array('required' => false)),
      'max_contents_per_page' => new sfValidatorInteger(),
      'structure'             => new sfValidatorString(array('max_length' => 255)),
      'uses_header'           => new sfValidatorBoolean(array('required' => false)),
      'uses_footer'           => new sfValidatorBoolean(array('required' => false)),
      'published'             => new sfValidatorBoolean(array('required' => false)),
      'is_enabled'            => new sfValidatorBoolean(array('required' => false)),
      'portal_id'             => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Portal'))),
      'type_id'               => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Type'))),
      'parent_id'             => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('Parent'), 'required' => false)),
      'created_at'            => new sfValidatorDateTime(),
      'updated_at'            => new sfValidatorDateTime(),
    ));

    $this->validatorSchema->setPostValidator(
      new sfValidatorAnd(array(
        new sfValidatorDoctrineUnique(array('model' => 'EmsSection', 'column' => array('portal_id', 'title'))),
        new sfValidatorDoctrineUnique(array('model' => 'EmsSection', 'column' => array('portal_id', 'slug'))),
      ))
    );

    $this->widgetSchema->setNameFormat('ems_section[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function getModelName()
  {
    return 'EmsSection';
  }

}
